home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / raid / strUtil.c < prev   
C/C++ Source or Header  |  1990-10-12  |  2KB  |  99 lines

  1. /* 
  2.  * strUtil.c --
  3.  *
  4.  * Copyright 1989 Regents of the University of California
  5.  * Permission to use, copy, modify, and distribute this
  6.  * software and its documentation for any purpose and without
  7.  * fee is hereby granted, provided that the above copyright
  8.  * notice appear in all copies.  The University of California
  9.  * makes no representations about the suitability of this
  10.  * software for any purpose.  It is provided "as is" without
  11.  * express or implied warranty.
  12.  */
  13.  
  14. #ifndef lint
  15. static char rcsid[] = "$Header: /sprite/src/kernel/raid/RCS/strUtil.c,v 1.5 90/10/12 14:01:17 eklee Exp $ SPRITE (Berkeley)";
  16. #endif /* not lint */
  17.  
  18. #include <ctype.h>
  19. #include <strings.h>
  20. #include "sprite.h"
  21. #include "fs.h"
  22.  
  23.  
  24. /*
  25.  *----------------------------------------------------------------------
  26.  *
  27.  * ScanLine --
  28.  *
  29.  *    Copy first line in ps1 to s2 replacing \n with \0.
  30.  *    Change ps1 to point to the 1st character of second line.
  31.  *
  32.  * Results:
  33.  *    NIL if no line is found s2 otherwise.
  34.  *
  35.  * Side effects:
  36.  *    ps1 points to next line.
  37.  *
  38.  *----------------------------------------------------------------------
  39.  */
  40.  
  41. char *
  42. ScanLine(ps1, s2)
  43.     char **ps1, *s2;
  44. {
  45.     char *s1, *retstr;
  46.  
  47.     retstr = s2;
  48.     s1 = *ps1;
  49.     while ( *s1 != '\0' && *s1 != '\n' ) {
  50.         *s2++ = *s1++;
  51.     }
  52.     if ( *s1 == '\0' ) {
  53.         return ( (char *) NIL );
  54.     }
  55.     *s2 = '\0';
  56.     *ps1 = s1+1;
  57.     return ( retstr );
  58. }
  59.  
  60.  
  61. /*
  62.  *----------------------------------------------------------------------
  63.  *
  64.  * ScanWord --
  65.  *
  66.  *    Copy first word in *ps1 to s2 (words are delimited by white space).
  67.  *    Change ps1 to point to the 2nd character after the first word
  68.  *    (i.e. skip over the delimiting whitespace).  This allows ps1 and
  69.  *    s2 to initially point to the same character string.
  70.  *
  71.  * Results:
  72.  *    Returns s2 or NIL if no word is found.
  73.  *
  74.  * Side effects:
  75.  *    ps1 points to the first character after the delimiting whitespace.
  76.  *
  77.  *----------------------------------------------------------------------
  78.  */
  79.  
  80. char *
  81. ScanWord(ps1, s2)
  82.     char **ps1, *s2;
  83. {
  84.     char *s1, *retstr;
  85.  
  86.     retstr = s2;
  87.     for ( s1 = *ps1; *s1 != '\0' && isspace(*s1); s1++ ) {
  88.     }
  89.     while ( *s1 != '\0' && !isspace(*s1) ) {
  90.         *s2++ = *s1++;
  91.     }
  92.     if ( *s1 == '\0' ) {
  93.         return ( (char *) NIL );
  94.     }
  95.     *s2 = '\0';
  96.     *ps1 = s1+1;
  97.     return ( retstr );
  98. }
  99.